package com.rc.saas.tenant.controller.statistics;

import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.WebPageInfo;
import com.rc.saas.tenant.common.constant.CommonConstant;
import com.rc.saas.tenant.model.tenant.TenantUser;
import com.rc.saas.tenant.service.order.OrderInfoService;
import com.rc.saas.tenant.shiro.ShiroUtils;
import com.rc.saas.tenant.vo.statistics.ChargingStatisticsVo;
import com.rc.saas.tenant.vo.statistics.OrderChargingStatisticsVo;
import com.rc.saas.tenant.vo.statistics.StatisticsQueryVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author frog
 * @date 2021/7/14
 */
@Controller
@RequestMapping("/chargingStatistics")
public class ChargingStatisticsController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private OrderInfoService orderInfoService;


    /**
     * 跳转充电量统计
     *
     * @return
     */
    @RequestMapping(value = "/index/tenantCode", method = RequestMethod.GET)
    public String chargingStatisticsTenantCode(Model model) {
        TenantUser sessionUser = ShiroUtils.getSessionUser();
        model.addAttribute("userType", CommonConstant.TENANT_CODE);
        model.addAttribute("code", sessionUser.getTenantCode());
        return "/templates/statistics/chargingStatistics";
    }

    /**
     * 跳转充电量统计
     *
     * @return
     */
    @RequestMapping(value = "/index/tenantOperatorCode", method = RequestMethod.GET)
    public String chargingStatisticsTenantOperatorCode(Model model) {
        TenantUser sessionUser = ShiroUtils.getSessionUser();
        model.addAttribute("userType", CommonConstant.TENANT_OPERATOR_CODE);
        model.addAttribute("code", sessionUser.getTenantOperatorCode());
        return "/templates/statistics/chargingStatistics";
    }


    /**
     * 返回充电量统计数据
     *
     * @return
     */
    @RequestMapping(value = "/listChargingStatistics", method = RequestMethod.GET)
    @ResponseBody
    public List<ChargingStatisticsVo> listChargingStatistics(StatisticsQueryVo statisticsQueryVO) {
        List<ChargingStatisticsVo> listChargingStatistics = orderInfoService.listChargingStatistics(statisticsQueryVO);
        return listChargingStatistics;
    }

    /**
     * 返回订单统计数据
     *
     * @return
     */
    @RequestMapping(value = "/listOrderChargingStatistics", method = RequestMethod.GET)
    @ResponseBody
    public WebPageInfo listOrderChargingStatistics(StatisticsQueryVo statisticsQueryVO) {
        PageInfo<OrderChargingStatisticsVo> pageInfo = orderInfoService.listOrderChargingStatistics(statisticsQueryVO);
        WebPageInfo webPageInfo = new WebPageInfo(pageInfo.getList(), Long.valueOf(pageInfo.getTotal()).intValue());
        return webPageInfo;
    }
}
